#include "worldTextBox.h"
#include "Global References/Globals.h"
using namespace wordModify;
//=====SET VALUES
void worldTextBox::init()
{
	Message = new char[maxMsgWidth*maxMessages];
	Message[0] = '\0';
}
//=====MUTATORS
void worldTextBox::update(){

	int totalMessageLength(0);
	int thisMessageLength(0);


	for(int i = 0; i < updateQueue.size(); i++){

		thisMessageLength = strLength(updateQueue.getByIndex(i));

		for(int x = 0; x < thisMessageLength; x++)
			Message[totalMessageLength + x] = updateQueue.getByIndex(i)[x];
		totalMessageLength+=thisMessageLength;
		Message[totalMessageLength]= '\n';
		totalMessageLength++;
	}

	Message[totalMessageLength] = '\0';
};
void worldTextBox::addMessage(char* message)
{
	if(message != ""){
		if(updateQueue.size() >= maxMessages)
			updateQueue.remove(0);
		updateQueue.push(message);
		update();
	}
};

//=====GET VALUES
int worldTextBox::totalCharCount()
{
	int total = 0;
	for(int i = 0; i < updateQueue.size(); ++i)
	{
		total += wordModify::strLength(updateQueue[i]);
	}

	return total;
}
//=====CLEAN UP
void worldTextBox::release()
{
	//TODO: This is where the bug is
	delete Message;
	Message = NULL;
	updateQueue.clear();
}